package com.qf.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsUser;
import com.qf.pojo.DtsUserAccount;
import com.qf.service.UserService;
import com.qf.util.ResponseUtil;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin("*")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/list")
    public Object list(String username, String mobile,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @RequestParam(defaultValue = "add_time") String sort,
                       @RequestParam(defaultValue = "desc") String order) {


        IPage<DtsUser> resultPage = userService.queryUserPage(username, mobile, page, limit, sort, order);

        List<DtsUser> list = resultPage.getRecords();
        long total = resultPage.getTotal();

        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", list);
        return ResponseUtil.ok(data);
    }

    /**
     * 会员审批
     */
    @RequestMapping("/approveAgency")
    public void approveAgency(){
    }

    /**
     * 会员推广代理
     *
     * @return
     */
    @RequestMapping("/detailApprove")
    public Object detailApprove(@RequestBody DtsUserAccount dtsUserAccount){
        Integer userId = dtsUserAccount.getUserId();
        DtsUserAccount userAccount = userService.selectUserAccountById(userId);

        Integer settlementRate = userAccount.getSettlementRate();

        Map<String, Object> data = new HashMap<>();
        data.put("settlementRate", settlementRate);

        return ResponseUtil.ok(data);
    }
}
